<template>
	<view class="app-code-layout">
		<l-painter isCanvasToTempFilePath @success="posterPath = $event" css="width: 630rpx; padding: 40rpx; borderRadius:20rpx; background: #fff;">
			<l-painter-view css="display:flex;justify-content:center;">
				<l-painter-text text="汇拓宝下载码"></l-painter-text>
			</l-painter-view>
			<l-painter-view css="display:flex;justify-content:center;padding:50rpx 0">
				<l-painter-image
				    src="/static/home/app_qrcode.png"
				    css="width: 400rpx; height: 400rpx"></l-painter-image
				>
			</l-painter-view>
			<l-painter-view css="display:flex;justify-content:center;">
				<l-painter-text :text="`推荐码(${userStore.user.qrCode})`" v-if="userStore.isAuth" @click="copyText"></l-painter-text>
			</l-painter-view>
		</l-painter>
		<view class="submit-btn" style="margin-top: 60rpx;" @tap="saveAction">保存相册分享</view>
	</view>

</template>

<script setup>
	import { ref } from 'vue';
	import { useUserStore } from '@/common/stores'
	const userStore = useUserStore()
	const posterPath = ref('')
	// 保存二维码
	const saveAction = () => {
		uni.$utils.showLoading('正在保存')
		uni.saveImageToPhotosAlbum({
			filePath:posterPath.value,
			success(res) {
				uni.$utils.showToast('保存成功')
			},
			fail(err) {
				uni.$utils.showToast('保存失败')
			}
		})
	}
	// 复制
	const copyText = ()=>{
		console.log('复制')
		//uni.$utils.copy(userStore.user.qrCode)
	}
</script>

<style lang="scss" scoped>
	.app-code-layout {
		padding: 60rpx;
		.app-code-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 40rpx;
			margin-bottom: 50rpx;
			font-size: 28rpx;

			text:nth-of-type(1) {
				margin-bottom: 50rpx;
			}

			text:nth-of-type(2) {
				margin-top: 50rpx;
			}

			.qrcode-box {
				width: 400rpx;
				height: 400rpx;
			}
		}
	}
</style>